Skip to content

Conversation

@sahilsanap101
Copy link

Pull Request for Stock Analyzer

Issue Title

feat: Implement robust YFinance API handling with batching, caching, and retries

Contributor Details

Closes

Closes #62

Describe Your Changes

Implemented comprehensive solution to reduce YFinance API rate-limit errors:

  • Batch Processing: Multiple tickers downloaded simultaneously
  • Intelligent Delays: Randomized 1-2 second delays between requests
  • Exponential Backoff: Automatic retries for failed requests (max 3 attempts)
  • Smart Caching: 24-hour CSV caching to prevent redundant downloads
  • Error Logging: Detailed error tracking in logs/errors.log
  • CLI Ready: Fully tested command-line interface on Windows

Screenshots

1.Single ticker download (AAPL)

Screenshot 2025-10-10 160302

2.Multi-ticker batch processing (MSFT, GOOGL, TSLA)
image

3.Test Using Tickers File
image

4.Test Error Handling
image

5.Verify Caching
image

(Add: CLI output, directory structure, cache validation screenshots)

Files Changed

  • fetch_stocks.py (main implementation)
  • requirements.txt (added new dependencies)
  • tickers.txt (sample tickers)
  • data/ (10 sample CSV files generated)
  • logs/errors.log (error tracking)

How Has This Been Tested?

Test Environment: Windows 11, Python 3.9
Test Coverage:

  • ✅ Single ticker download (AAPL)
  • ✅ Multi-ticker batch processing (MSFT, GOOGL, TSLA)
  • ✅ CSV caching validation (24-hour TTL working)
  • ✅ Error logging system verification
  • ✅ CLI interface testing
  • ✅ Directory structure creation

How Has This Been Tested?

Cache System Validation:

  • File-based processing: python fetch_stocks.py --tickers-file tickers.txt
  • All 10 tickers correctly identified as cached ("Up-to-date")
  • 24-hour TTL working perfectly - prevents unnecessary API calls

Batch Processing:

  • Multiple tickers: python fetch_stocks.py --tickers MSFT GOOGL TSLA --batch-size 2
  • Configurable batch size working correctly

Error Handling:

  • Invalid tickers properly logged with exponential backoff retries
  • Mixed valid/invalid ticker files processed gracefully
  • Comprehensive error logging in logs/errors.log

Performance:

  • 100% cache hit rate for recent data
  • Zero API calls when data is fresh
  • Efficient batch downloading when needed

Type of Change

Checklist

  • [✅] My code follows the project's guidelines
  • [✅] Self-review completed
  • [✅] Comments added for complex logic
  • [✅] Documentation updated
  • [✅] No new warnings generated
  • [✅] Screenshots included (pending)
  • [✅] Dependent changes handled

@github-actions
Copy link

Thanks for opening this Pull Request! A maintainer will review it shortly. Please make sure you've followed all contribution guidelines.

Join our Discord Community for discussions, questions, and real-time collaboration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Major Update!] : New update regarding to reduce Yfinance API limit Error

1 participant